<template>
  <div class="context-menu" v-show="visible" :style="{top: y + 'px', left: x + 'px'}">
    <ul>
      <li @click="onMenuItemClick('copy')">Copy</li>
      <li @click="onMenuItemClick('paste')">Paste</li>
      <li @click="onMenuItemClick('delete')">Delete</li>
    </ul>
  </div>
</template>

<script>
export default {
  props: {
    x: Number,
    y: Number,
    visible: Boolean
  },
  methods: {
    onMenuItemClick (action) {
      this.$emit('operate', action)
    }
  }
}
</script>

<style>
.context-menu {
  position: absolute;
  transform: translateX(-50%);
  background-color: #fff;
  border: 1px solid #ccc;
  padding: 5px;
  z-index: 100;
}
.context-menu ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.context-menu li {
  cursor: pointer;
  padding: 5px;
}
.context-menu li:hover {
  background-color: #f1f1f1;
}
</style>
